import argparse, json, pandas as pd
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
from metrics.healpix_chi2 import healpix_chi2
from metrics.ripleyK_sphere import ripley_L
from metrics.min_sep import min_sep
from metrics.wahba_cond import wahba_cond
from preprocess.preprocess import load_catalog

if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("--catalog", required=True)
    ap.add_argument("--out", required=True)
    args = ap.parse_args()

    # df = pd.read_csv(args.catalog)
    df = load_catalog(args.catalog)
    results = {
        "HEALPix_chi2": healpix_chi2(df),
        "Ripley_L": ripley_L(df),
        "min_sep": min_sep(df),
        "condK": wahba_cond(df),
        "N": int(len(df))
    }
    print(results)
    with open(args.out, "w") as f:
        json.dump(results, f, indent=2)

# Example usage:
# (env_pytorch) sam@PC-Sam:/home/prj_li/ir-gsc$ python src/baselines/run_baselines.py --catalog data/ir_catalog.csv --out figs/baselines.json
# <frozen importlib._bootstrap>:219: RuntimeWarning: scipy._lib.messagestream.MessageStream size changed, may indicate binary incompatibility. Expected 56 from C header, got 64 from PyObject
# {'HEALPix_chi2': 3.2244883188448146, 'Ripley_L': 0.018783264327786865, 'min_sep': 0.0, 'condK': 2.14897364091557, 'N': 291772}